package com.general;

import com.hazelcast.client.HazelcastClient;
import com.hazelcast.client.config.ClientConfig;
import com.hazelcast.config.InvalidConfigurationException;
import com.hazelcast.core.HazelcastInstance;

/**
 * @description: HazelcastInstance对象holder
 * @author: general
 * @version: 1.0
 * @create: 2022-04-10 16:58
 **/
public class HazelcastInstanceHolder {

    private static volatile HazelcastInstance singleton;

    static {
        ClientConfig clientConfig = new ClientConfig();
        clientConfig.setClusterName("hello-world");
        try {
            singleton = HazelcastClient.newHazelcastClient(clientConfig);
        }catch (InvalidConfigurationException e){
            // ignore exists
        }
    }


    /**
     * 获取一个HazelcastInstance实例
     * @return
     */
    public static HazelcastInstance getInstance() {
        return singleton;
    }

}
